package com.yunc.modules.shop.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunc.base.controller.ShopBaseController;
import com.yunc.base.utils.R;
import com.yunc.modules.shop.entity.ShopOrder;
import com.yunc.modules.shop.entity.dto.ShopOrderDTO;
import com.yunc.modules.shop.service.IShopOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 订单管理
 *
 * @author congcong tao
 * @date 2018/12/24 9:15
 */
@RestController
@RequestMapping("shopOrder")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ShopOrderController extends ShopBaseController {

    private final IShopOrderService shopOrderService;

    @GetMapping("/page")
    public R page(Page<ShopOrderDTO> page, ShopOrder order){
        setShopId(order);
        shopOrderService.pageInfo(page, order);
        return R.ok().put("data", page.getRecords()).put("count", page.getTotal());
    }

    @GetMapping("/info/{orderId}")
    public R info(@PathVariable String orderId){
        ShopOrder order = shopOrderService.getById(orderId);
        return R.ok().put("order", order);
    }
}
